import { loginAPI } from '@/api/user.js'
import { setToken, getToken, delToken } from '@/utils/storage.js'
export default {
  state () {
    return {
      token: getToken() || '',

    }
  },
  mutations: {
    changeToken (state, token) {
      state.token = token
    },
    clearToken (state) {
      delToken()
    }
  },
  actions: {
    // 发送登录请求
    async syncLogin ({ commit }, data) {
      const res = await loginAPI(data)
      // const token = res.data.token
      console.log(res, 876);

      setToken(res.data.token)
      console.log(getToken(), 'ppp');
      commit('changeToken', res.data.token)

    },

    async syncloginout ({ commit }) {
      console.log(112233);
      commit('clearToken')
    }
  },
  getters: {

  },
  namespaced: true
}